// ----------------------------------
// RSDK Project: Sonic Essence
// Script Description: ToxiFrog
// Script Author: Tails LP
// ----------------------------------

//-------Aliases-------//


// States
private alias 0 : IDLE
private alias 1 : CLIMB
private alias 2 : ATTACK
private alias 3 : JUMP


private alias object.value0 : frog.timer
private alias object.value1 : climb.direction
private alias object.value2 : ani.timer

private alias object.value38 : player.hitboxLeft
private alias object.value39 : player.hitboxRight
private alias object.value40 : player.hitboxTop
private alias object.value41 : player.hitboxBottom

//-------Function declarations-------//

//-------Static Values-------//

//-------Tables-------//


//-------Functions-------//


event ObjectMain
	switch object.state
	case IDLE
		frog.timer ++
		if frog.timer >= 30
			frog.timer = 0
			object.state = CLIMB
		endif
		break
	case CLIMB
	
		frog.timer ++
		if frog.timer >= 120
			climb.direction ^= 1
			frog.timer = 0
			object.state = IDLE
		endif
		
		if climb.direction == 0
			object.ypos += 0x6000
		else
			object.ypos -= 0x6000
		endif
		break
	case ATTACK
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)

			if object[currentPlayer].xpos < object.xpos
				object.direction = FLIP_X
			else
				object.direction = FLIP_NONE
			endif
		next
		break
	case JUMP
		break
	endswitch
	
	if object.state < ATTACK
		BoxCollisionTest(C_TOUCH, object.entityPos, -136, -64, 136, 64, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
		if checkResult == TRUE
			object.state = ATTACK
		endif
	endif
	
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		BoxCollisionTest(C_TOUCH, object.entityPos, -10, -18, 10, 10, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
		if checkResult == true
			CallFunction(PlayerObject_BadnikBreak)
		endif
	next
	
end event

event ObjectDraw

	ani.timer ++
		
	switch object.state
	case IDLE
		object.frame = 0
		break
	case CLIMB
	
		if ani.timer > 7
			object.frame ++
			ani.timer = 0
		endif
	
		if object.frame < 1
			object.frame = 1
		endif
		if object.frame > 4
			object.frame = 1
		endif
		break
	case ATTACK
		switch ani.timer
		case 0
			object.frame = 1
			break
		case 20
			object.frame = 5
			break
		case 30
			object.frame = 6
			break
		case 40
			if object.direction == FLIP_NONE
				CreateTempObject(TypeName[ToxiFrog Shot], 0, object.xpos, object.ypos)
				object[tempObjectPos].ypos -= 0xA0000
				object[tempObjectPos].xvel = 0x10000
				object[tempObjectPos].yvel = -0x40000
			else
				CreateTempObject(TypeName[ToxiFrog Shot], 0, object.xpos, object.ypos)
				object[tempObjectPos].ypos -= 0xA0000
				object[tempObjectPos].xvel = -0x10000
				object[tempObjectPos].yvel = -0x40000
			endif
			break
		case 70
			object.frame = 5
			break
		case 80
			object.frame = 1
			ani.timer = 0
			object.state = CLIMB
			break
		endswitch
		break
	case JUMP
		break
	endswitch
	
	DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
end event

event ObjectStartup
	foreach (TypeName[ToxiFrog], arrayPos1, ACTIVE_ENTITIES)
		frog[arrayPos1].timer = 42
	next
    LoadSpriteSheet("SSZ/Objects.gif")
	SpriteFrame(-18, -18, 36, 36, 133, 167)		// 00 Idle
	
	SpriteFrame(-18, -24, 35, 47, 170, 167)		// 01 Climb 1a
	SpriteFrame(-20, -18, 38, 38, 206, 167)		// 02 Climb 2a
	SpriteFrame(-18, -18, 38, 38, 242, 206)		// 03 Climb 1b
	SpriteFrame(-17, -24, 35, 47, 206, 206)		// 04 Climb 2b

	SpriteFrame(-18, -24, 35, 47, 133, 204)		// 05 Attack 1
	SpriteFrame(-18, -24, 35, 47, 170, 215)		// 06 Attack 2

	SpriteFrame(-20, -17, 33, 25, 290, 170)		// 07 Jump 1
	SpriteFrame(-22, -12, 36, 20, 324, 170)		// 08 Jump 2
	SpriteFrame(-20, -12, 34, 20, 361, 170)		// 09 Jump 3
	SpriteFrame(-26, -23, 44, 33, 245, 167)		// 10 Jump 4
	
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-18, -18, 36, 36, 133, 167)
end event